/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JPanelRelacionar.java
 *
 * Created on 16/05/2012, 02:11:15 AM
 */
package vista.panel;

import controlador.ControladorJPanelRelacionar;
import modelo.Amigo;
import modelo.Seccion;

/**
 *
 * @author Elias Mendoza
 */

public class JPanelRelacionar extends javax.swing.JPanel {

  /** Creates new form JPanelRelacionar */
  static ControladorJPanelRelacionar accion;
  private static JPanelRelacionar panelRelacionar = null;
  private JPanelRelacionar() {
    initComponents();
    accion = new ControladorJPanelRelacionar();
    accion.llenarJComboAmigos(jComboBoxAmigo);
    accion.llenarJComboSecciones(jComboBoxSeccion);
  }

    public static JPanelRelacionar getPanelRelacionar() {
        if(panelRelacionar == null){
            panelRelacionar =  new JPanelRelacionar();
        }
        return panelRelacionar;
    }
  

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        jComboBoxSeccion = new javax.swing.JComboBox();
        jComboBoxAmigo = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabelAmigo = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jListSecciones = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        jListAmigos = new javax.swing.JList();
        jLabelSeccion = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jButtonRefrescar = new javax.swing.JButton();

        setBackground(new java.awt.Color(255, 255, 255));
        setLayout(new java.awt.GridBagLayout());

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setLayout(new java.awt.GridBagLayout());

        jComboBoxSeccion.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxSeccionItemStateChanged(evt);
            }
        });
        jComboBoxSeccion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxSeccionActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.ipadx = 55;
        gridBagConstraints.ipady = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(3, 37, 0, 0);
        jPanel1.add(jComboBoxSeccion, gridBagConstraints);

        jComboBoxAmigo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxAmigoItemStateChanged(evt);
            }
        });
        jComboBoxAmigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxAmigoActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.ipadx = 255;
        gridBagConstraints.ipady = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(3, 28, 0, 0);
        jPanel1.add(jComboBoxAmigo, gridBagConstraints);

        jButton1.setText("Relacionar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 28, 0, 37);
        jPanel1.add(jButton1, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridy = 3;
        add(jPanel1, gridBagConstraints);

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabelAmigo.setFont(new java.awt.Font("Maiandra GD", 1, 12));
        jLabelAmigo.setText("Amigo");

        jScrollPane1.setViewportView(jListSecciones);

        jScrollPane2.setViewportView(jListAmigos);

        jLabelSeccion.setFont(new java.awt.Font("Maiandra GD", 1, 12));
        jLabelSeccion.setText("Seccion");

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelAmigo, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 303, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelSeccion, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabelAmigo, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabelSeccion, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE)))))
                .addContainerGap())
        );

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridy = 4;
        add(jPanel2, gridBagConstraints);

        jButtonRefrescar.setText("refrescar");
        jButtonRefrescar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRefrescarActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 13, 0);
        add(jButtonRefrescar, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

  private void jComboBoxSeccionItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxSeccionItemStateChanged
    // TODO add your handling code here:
    
  }//GEN-LAST:event_jComboBoxSeccionItemStateChanged

  private void jComboBoxAmigoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxAmigoItemStateChanged
    // TODO add your handling code here:
    
  }//GEN-LAST:event_jComboBoxAmigoItemStateChanged

  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    accion.realacionar((Seccion) jComboBoxSeccion.getSelectedItem(), (Amigo) jComboBoxAmigo.getSelectedItem());
    accion.llebarListaAmigosBySeccion(jComboBoxSeccion, jLabelSeccion, jListAmigos);
    accion.llebarListaSeccionesByAmigo(jComboBoxAmigo, jLabelAmigo, jListSecciones);
  }//GEN-LAST:event_jButton1ActionPerformed

private void jButtonRefrescarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRefrescarActionPerformed
// TODO add your handling code here:
    accion.llenarJComboAmigos(jComboBoxAmigo);
    accion.llenarJComboSecciones(jComboBoxSeccion);
}//GEN-LAST:event_jButtonRefrescarActionPerformed

private void jComboBoxSeccionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxSeccionActionPerformed
// TODO add your handling code here:
    accion.llebarListaAmigosBySeccion(jComboBoxSeccion, jLabelSeccion, jListAmigos);
}//GEN-LAST:event_jComboBoxSeccionActionPerformed

private void jComboBoxAmigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxAmigoActionPerformed
// TODO add your handling code here:
    accion.llebarListaSeccionesByAmigo(jComboBoxAmigo, jLabelAmigo, jListSecciones);
}//GEN-LAST:event_jComboBoxAmigoActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonRefrescar;
    private javax.swing.JComboBox jComboBoxAmigo;
    private javax.swing.JComboBox jComboBoxSeccion;
    private javax.swing.JLabel jLabelAmigo;
    private javax.swing.JLabel jLabelSeccion;
    private javax.swing.JList jListAmigos;
    private javax.swing.JList jListSecciones;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    // End of variables declaration//GEN-END:variables
}
